#include "probar.h"
#include <unistd.h>
#include <string.h>
//实现

#define STYLE '='

void probar(double total , double cur)
{
	char buff[101];
	memset(buff, 0 , sizeof(buff));
	//旋转光标
	char st[] = "/-\\";
	int len = strlen(st);

	//自动填充
	//计算填充字符大小 
	int num = (int)(cur*100 / total);
	//自动填充	
	for(int i = 0; i < num; ++i)
	{
		buff[i] = STYLE;	
	}			
	
	//旋转光标要用新的计数 ,看调用了多少次	
	static int ans = 0;
	ans %= len;
	double rate = cur / total;
	printf("[%-100s][%.2lf%%][%c]\r",buff,rate*100,st[ans]);
	usleep(4000);	
	fflush(stdout);
	ans++;
}
